var express = require('express');
var router = express.Router();
const {User,Laboratory,Equipment,bookinfo} = require('../models')
/* GET home page. */
console.log(User);
console.log(Laboratory);
console.log(Equipment);
console.log(bookinfo);

router.get('/',async function(req, res, next) {
  const condition = {
    include:[
      {
        model:User,
        as:'User',
        attributes:['id','account','name']
      },
      {
        model:Laboratory,
        as:'Laboratory',
        attributes:['id','laboratoryName']
      },
      {
        model:Equipment,
        as:'Equipment',
        attributes:['id','equipmentName']
      },
    ]
  }
  const infos = await bookinfo.findAll(condition)
  const equipments = await Equipment.findAll({
    include:[
    {
      model:Laboratory,
      as:'Laboratory',
      attributes:['id','laboratoryName']
    },
    {
      model:bookinfo,
      as:'bookinfos',
      attributes:['id'],
      include:[
        {
          model:User,
          as:'User',
          attributes:['id','account'],
        }
      ]
    },
  ]})
  res.json({ infos,equipments });
});

module.exports = router;
